package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.NumericalLimitsPoJo;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.CreditFixedLimitEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author xingxing.xiao
 */
@Getter
public enum TempCreditFixedLimitDistributorEnum {

    BASE_INFO(CreditFixedLimitEnum.BASE_INFO),
    CREDIT_FIXED_NO(CreditFixedLimitEnum.CREDIT_FIXED_NO),
    CUSTOMER_ID(CreditFixedLimitEnum.CUSTOMER_ID),
    OLD_LIMIT(CreditFixedLimitEnum.OLD_LIMIT),
    APPLY_LIMIT(CreditFixedLimitEnum.APPLY_LIMIT),
    MODIFY_REASON(CreditFixedLimitEnum.MODIFY_REASON),
    APPLY_ID(CreditFixedLimitEnum.APPLY_ID),
    APPLY_TIME(CreditFixedLimitEnum.APPLY_TIME),
    SYSTEM_INFO(CreditFixedLimitEnum.SYSTEM_INFO),
    CREATOR_ID(CreditFixedLimitEnum.CREATOR_ID),
    ADD_TIME(CreditFixedLimitEnum.ADD_TIME),
    UPDATE_TIME(CreditFixedLimitEnum.UPDATE_TIME),
    CUSTOMER_NAME(CreditFixedLimitEnum.CUSTOMER_NAME),
    APPLY_NAME(CreditFixedLimitEnum.APPLY_NAME),
    CREDIT_ID(CreditFixedLimitEnum.CREDIT_ID),
    ;

    private CreditFixedLimitEnum anEnum;

    TempCreditFixedLimitDistributorEnum(CreditFixedLimitEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCreditFixedLimitDistributorEnum> getAllEnum() {
        List<TempCreditFixedLimitDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initCreditFixedNo(FieldAttrEntity fieldAttrEntity) {
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.CREDIT_FIXED_LIMIT.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(CREDIT_FIXED_NO.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setSerialNumber(InitExplainsHelper.setSerialNumber(SerialNumberEnum.CREDIT_FIXED_NO));
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initCustomerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        saasParticularAttributePoJo.setRelyMode("customer");
        saasParticularAttributePoJo.setRelyType("base");
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    /**
     * 原固定额度
     * @param fieldAttrEntity
     */
    public static void initOldLimit(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initApplyLimit(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setNumericalLimitsFlag(1);
        fieldAttrEntity.setNumericalLimits(new NumericalLimitsPoJo(0D, 100000000000D));
    }

    /**
     * 可见置灰
     * :visible-disabled="fieldInfo.isForbidden === 0 && fieldInfo.visible === 1"
     */
    public static void initModifyReason(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initApplyId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    /**
     * 日期设置为当前时间
     * @param fieldAttrEntity
     */
    public static void initApplyTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setDateType( DateTimeEnum.TIME.getType());
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("today");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setShowEditable(0);
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

}
